import requests
from bs4 import BeautifulSoup
import os

# 目标网页URL
url = 'http://10.48.2.250/result.html'

# 发送HTTP请求获取网页内容
response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 使用BeautifulSoup解析网页内容
    soup = BeautifulSoup(response.content, 'html.parser')
    
    # 提取网页中的文字内容
    text = soup.get_text()
    
    # 获取桌面路径
    desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop')
    
    # 文件名
    filename = 'result.txt'
    
    # 文件路径
    file_path = os.path.join(desktop_path, filename)
    
    # 将提取的文字内容保存到桌面
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(text)
    
    print(f'文字内容已保存到桌面文件 {filename}')
else:
    print(f'请求失败，状态码：{response.status_code}')
